package com.doge.controller.admin.promotion;

import com.doge.bean.base.BaseData;
import com.doge.bean.base.BaseParam;
import com.doge.bean.base.BaseRespVo;
import com.doge.bean.bo.topic.TopicBatchDelBO;
import com.doge.bean.pojo.topic.Topic;
import com.doge.bean.vo.topic.TopicReadVO;
import com.doge.service.admin.promotion.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * promotion包里面全是推广模块相关的
 * TopicController是推广模块里面的专题管理
 * Created By ntian
 */
@RestController
@RequestMapping("admin/topic")
public class TopicController {
    @Autowired
    TopicService topicService;
    /**
     * GET
     * /admin/topic/list?page=1&limit=20&title=设计师&subtitle=原创&sort=add_time&order=desc
     */
    @GetMapping("list")
    public BaseRespVo listTopic(BaseParam baseParam,String title,String subtitle){
        BaseData data = topicService.listTopic(baseParam,title,subtitle);
        return BaseRespVo.ok(data);
    }

    /**
     * POST /admin/topic/create
     * 创建某一个推广专题
     */
    @PostMapping("create")
    public BaseRespVo createTopic(@RequestBody Topic topic){
        Topic topic1 = topicService.createTopic(topic);
        return BaseRespVo.ok(topic1);
    }

    /**
     * POST /admin/topic/update
     * 修改某一个专题
     */
    @PostMapping("update")
    public BaseRespVo updateTopic(@RequestBody Topic topic){
        Topic topic1 = topicService.updateTopic(topic);
        return BaseRespVo.ok(topic1);
    }

    /**
     * GET /admin/topic/read?id=315
     * 修改某一个专题的时候的回显数据
     */
    @GetMapping("read")
    public BaseRespVo readTopic(Integer id){
        TopicReadVO topic = topicService.readTopic(id);
        return BaseRespVo.ok(topic);
    }
    /**
     * POST /admin/topic/delete
     * 删除一个推广模块里的专题
     */
    @PostMapping("delete")
    public BaseRespVo deleteTopic(@RequestBody Topic topic) throws Exception {
        int rows = topicService.deleteTopic(topic);
        return BaseRespVo.ok(null);
    }

    /**
     * POST admin/topic/batch-delete
     * 批量删除专题
     */

    @PostMapping("batch-delete")
    public BaseRespVo batchDelete(@RequestBody TopicBatchDelBO bo) throws Exception {
        int rows = topicService.batchDelete(bo.getIds());
        return BaseRespVo.ok(null);
    }






}